package cs3343.project.family;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;

import cs3343.project.family.UI.*;

/**
 * The Class UIController.
 */
public class UIController {
	
	/** The gc. */
	private GameController gc;
	
	/** The welcome frame. */
	private WelcomeFrame welcomeFrame;
	
	/** The character frame. */
	private CharacterFrame characterFrame;
	
	/** The endgame frame. */
	private EndGameFrame endgameFrame;
	
	/** The game frame. */
	private GameFrame gameFrame;
	
	/** The eventcard frame. */
	private EventCardFrame eventcardFrame;
	
	/** The toolcard frame. */
	private ToolCardFrame toolcardFrame;
	
	/** The yesno frame. */
	private YesNoFrame yesnoFrame;
	
	/** The game setting frame. */
	private GameSettingFrame gameSettingFrame;
	
	/** The global game stat frame. */
	private GlobalGameStatFrame globalGameStatFrame;
	
	/** The game stat frame. */
	private GameStatFrame gameStatFrame;
	
	/** The profile create frame. */
	private ProfileCreateFrame profileCreateFrame;
	
	/** The profile create frame. */
	private CreateCardFrame createCardFrame;
	
	/**
	 * Instantiates a new uI controller.
	 *
	 * @param gc the gc
	 */
	public UIController(GameController gc) {
		this.gc = gc;
	}
	
	/**
	 * Release resource.
	 */
	public void releaseResource() {
		if (gameFrame != null)
			gameFrame.dispose();
	}
	
	/**
	 * Show welcome frame.
	 */
	public void showWelcomeFrame() {
		welcomeFrame = new WelcomeFrame(gc);
		welcomeFrame.setVisible(true);		
	}
	
	/**
	 * Show character frame.
	 */
	public void showCharacterFrame() {
		characterFrame = new CharacterFrame(gc);
		characterFrame.setVisible(true);
	}
	
	/**
	 * Hide character frame.
	 */
	public void hideCharacterFrame() {
		characterFrame.setVisible(false);
	}
	
	/**
	 * Show game frame.
	 *
	 * @param noOfPlayers the no of players
	 */
	public void showGameFrame(int noOfPlayers) {
		int[] dimension = new int[2];
		if (noOfPlayers <= 2) {
			dimension[0] = 816;
			dimension[1] = 727;
		}
		else if (noOfPlayers > 2 && noOfPlayers <= 4) {
			dimension[0] =  1016;
			dimension[1] = 727;
		}
		else {
			dimension[0] = 1216;
			dimension[1] = 727;
		}
		gameFrame = new GameFrame(dimension[0], dimension[1], gc);
		gameFrame.setVisible(true);
	}
	
	/**
	 * Hide game frame.
	 */
	public void hideGameFrame() {
		gameFrame.setVisible(false);
	}
	
	/**
	 * Show end game frame.
	 */
	public void showEndGameFrame() {
		endgameFrame = new EndGameFrame(gc);
		endgameFrame.setVisible(true);
	}
	
	/**
	 * Hide end game frame.
	 */
	public void hideEndGameFrame() {
		endgameFrame.setVisible(false);
	}
	
	/**
	 * Show profile create frame.
	 */
	public void showProfileCreateFrame() {
		profileCreateFrame = new ProfileCreateFrame(gc);
		profileCreateFrame.setVisible(true);
	}
	
	/**
	 * Hide profile create frame.
	 */
	public void hideProfileCreateFrame() {
		profileCreateFrame.setVisible(false);
	}
	
	/**
	 * Show event card frame.
	 *
	 * @param card the card
	 * @param character the character
	 */
	public void showEventCardFrame(Card card, Character character) {
		eventcardFrame = new EventCardFrame(character, card, gc);
		eventcardFrame.setVisible(true);
	}
	
	/**
	 * Hide event card frame.
	 */
	public void hideEventCardFrame() {
		eventcardFrame.setVisible(false);
	}
	
	/**
	 * Show tool card frame.
	 *
	 * @param card the card
	 * @param character the character
	 * @param type the type
	 */
	public void showToolCardFrame(Card card, Character character, String type) {
		toolcardFrame = new ToolCardFrame(character, card, type, gc);
	}
	
	/**
	 * Hide tool card frame.
	 */
	public void hideToolCardFrame() {
		toolcardFrame.setVisible(false);
	}
	
	/**
	 * Show yes no frame.
	 *
	 * @param card the card
	 * @param character the character
	 * @param type the type
	 */
	public void showYesNoFrame(Card card, Character character, String type) {
		yesnoFrame = new YesNoFrame(character, card, type, gc);
		yesnoFrame.setVisible(true);
	}
	
	/**
	 * Hide yes no frame.
	 */
	public void hideYesNoFrame() {
		yesnoFrame.setVisible(false);
	}
	
	/**
	 * Show game setting frame.
	 */
	public void showGameSettingFrame() {
		gameSettingFrame = new GameSettingFrame(gc);
		gameSettingFrame.setVisible(true);
	}
	
	/**
	 * Hide game setting frame.
	 */
	public void hideGameSettingFrame() {
		gameSettingFrame.setVisible(false);
	}
	
	/**
	 * Show global game stat frame.
	 */
	public void showGlobalGameStatFrame() {
		globalGameStatFrame = new GlobalGameStatFrame(gc);
		globalGameStatFrame.setVisible(true);
	}
	
	/**
	 * Show game stat frame.
	 */
	public void showGameStatFrame() {
		gameStatFrame = new GameStatFrame(gc, "Change of Self-Esteem Point", 
											"Game Turn", "Self-Esteem Point");
		gameStatFrame.setVisible(true);
	}
	
	/**
	 * Show game stat frame.
	 */
	public void showCreateCardFrame() {
		createCardFrame = new CreateCardFrame(gc);
		createCardFrame.setVisible(true);
	}	
	
	/**
	 * Hide global game stat frame.
	 */
	public void hideGlobalGameStatFrame() {
		globalGameStatFrame.setVisible(false);
	}
	
	/**
	 * Frame centering.
	 *
	 * @param frame the frame
	 */
	public void frameCentering(JFrame frame) {
		// Get the size of the screen
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		 
		// Determine the new location of the window
		int w = frame.getSize().width;
		int h = frame.getSize().height;
		int x = (dim.width - w)/2;
		int y = (dim.height - h)/2;
		 
		// Move the window
		frame.setLocation(x, y);
	}

	/**
	 * Gets the character frame.
	 *
	 * @return the character frame
	 */
	public CharacterFrame getCharacterFrame() {
		return characterFrame;
	}

	/**
	 * Sets the character frame.
	 *
	 * @param characterFrame the new character frame
	 */
	public void setCharacterFrame(CharacterFrame characterFrame) {
		this.characterFrame = characterFrame;
	}

	/**
	 * Gets the endgame frame.
	 *
	 * @return the endgame frame
	 */
	public EndGameFrame getEndgameFrame() {
		return endgameFrame;
	}

	/**
	 * Sets the endgame frame.
	 *
	 * @param endgameFrame the new endgame frame
	 */
	public void setEndgameFrame(EndGameFrame endgameFrame) {
		this.endgameFrame = endgameFrame;
	}

	/**
	 * Gets the game frame.
	 *
	 * @return the game frame
	 */
	public GameFrame getGameFrame() {
		return gameFrame;
	}

	/**
	 * Sets the game frame.
	 *
	 * @param gameFrame the new game frame
	 */
	public void setGameFrame(GameFrame gameFrame) {
		this.gameFrame = gameFrame;
	}
	
	/**
	 * Gets the eventcard frame.
	 *
	 * @return the eventcard frame
	 */
	public EventCardFrame getEventcardFrame() {
		return eventcardFrame;
	}

	/**
	 * Gets the welcome frame.
	 *
	 * @return the welcome frame
	 */
	public WelcomeFrame getWelcomeFrame() {
		return welcomeFrame;
	}

	/**
	 * Sets the welcome frame.
	 *
	 * @param welcomeFrame the new welcome frame
	 */
	public void setWelcomeFrame(WelcomeFrame welcomeFrame) {
		this.welcomeFrame = welcomeFrame;
	}

	/**
	 * Gets the toolcard frame.
	 *
	 * @return the toolcard frame
	 */
	public ToolCardFrame getToolcardFrame() {
		return toolcardFrame;
	}

	/**
	 * Sets the toolcard frame.
	 *
	 * @param toolcardFrame the new toolcard frame
	 */
	public void setToolcardFrame(ToolCardFrame toolcardFrame) {
		this.toolcardFrame = toolcardFrame;
	}

	/**
	 * Gets the yesno frame.
	 *
	 * @return the yesno frame
	 */
	public YesNoFrame getYesnoFrame() {
		return yesnoFrame;
	}

	/**
	 * Sets the yesno frame.
	 *
	 * @param yesnoFrame the new yesno frame
	 */
	public void setYesnoFrame(YesNoFrame yesnoFrame) {
		this.yesnoFrame = yesnoFrame;
	}

	/**
	 * Gets the game setting frame.
	 *
	 * @return the game setting frame
	 */
	public GameSettingFrame getGameSettingFrame() {
		return gameSettingFrame;
	}

	/**
	 * Sets the game setting frame.
	 *
	 * @param gameSettingFrame the new game setting frame
	 */
	public void setGameSettingFrame(GameSettingFrame gameSettingFrame) {
		this.gameSettingFrame = gameSettingFrame;
	}

	/**
	 * Gets the profile create frame.
	 *
	 * @return the profile create frame
	 */
	public ProfileCreateFrame getProfileCreateFrame() {
		return profileCreateFrame;
	}

	/**
	 * Sets the profile create frame.
	 *
	 * @param profileCreateFrame the new profile create frame
	 */
	public void setProfileCreateFrame(ProfileCreateFrame profileCreateFrame) {
		this.profileCreateFrame = profileCreateFrame;
	}

	/**
	 * Sets the eventcard frame.
	 *
	 * @param eventcardFrame the new eventcard frame
	 */
	public void setEventcardFrame(EventCardFrame eventcardFrame) {
		this.eventcardFrame = eventcardFrame;
	}
	
	/**
	 * Disable all button.
	 */
	public void disableAllButton(){
		gameFrame.disableAllButton();
	}
	
	/**
	 * Enable dice button.
	 */
	public void enableDiceButton(){
		gameFrame.enableDiceButton();
	}
}
